using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Robot.Business;
using Robot.Data;
using Robot.Entities;
using ExpertPdf;
using System.IO;
using Scb.Framework;

namespace WebRobot.App_code
{
  public class FXFile
  {
    #region Variable Declarations

    private string _FileName = "";

    #endregion

    #region properties

    public string FileName
    {
      get { return _FileName; }
      set { _FileName = value; }
    }

    #endregion

    #region Help

    public string GetBranchFX(string sLine)
    {
      string branch = "";
      string[] s = sLine.Split(' ');
      int count = 0;
      for (int i = 0; i < s.Length; i++)
      {
        if (s[i] != "")
        {
          if (count == 2)
          {
            branch = s[i];
            break;
          }
          count++;
        }
      }

      return branch;
    }

    public string GetCustumerNameFX(string sLine)
    {
      return sLine.Trim();
    }

    public bool IsTransaction(string sLine)
    {
      int count = 0;
      foreach (string s in sLine.Split(' '))
      {
        if (s != "")
        {
          count++;
        }
      }
      if (count == 13 || count == 12)
        return true;
      return false;
    }

    public tblImportTransaction GetTransactionFX(string sLine, string peoplewise,DateTime createDate)
    {
      int count = 0;
      tblImportTransaction Trax = new tblImportTransaction();


      Trax.CreatedDate = createDate;
      Trax.FromFileID = tblFileUploadService.GettblFileUploadByFileName(FileName, peoplewise).ID;
      string[] sSplit = sLine.Split(' ');
      foreach (string s in sSplit)
      {
        if (s != "")
          count++;
      }
      #region transaction 13 column
      if (count == 13)
      {
        count = 0;
        foreach (string s in sSplit)
        {
          if (s != "")
          {
            try
            {
              count++;
              switch (count)
              {
                case 1:// chanel
                  Trax.Channel = s;
                  break;
                case 2://Batch No
                  Trax.BatchNo = s;
                  break;
                case 3://Buy Ccr
                  Trax.BuyCurrency = s;
                  break;
                case 4://Buy Amount
                  Trax.BuyAmount = decimal.Parse(s);
                  break;
                case 5://Customer rate
                  Trax.CusRate = decimal.Parse(s);
                  break;
                case 6://Sell Ccr
                  Trax.SellCurrency = s;
                  break;
                case 7://Sell Amount

                  Trax.SellAmount = decimal.Parse(s);

                  break;
                case 11://Value date

                  Trax.ValueDate = DateTime.Parse(s);


                  break;
                case 12://Cus seg
                  Trax.CusSeg = s;
                  break;
                case 13://Cust Master No
                  Trax.CustMasterNo = s;
                  break;
              }
            }
            catch (Exception ex)
            {
              Logger.Error("WebRobot.App_code.FXFile::GetTransactionFX::transaction 13 column", ex);
            }
          }
        }
      }
      #endregion

      #region transaction 12 column
      else if (count == 12)
      {
        count = 0;
        foreach (string s in sSplit)
        {
          if (s != "")
          {
            try
            {
              count++;
              switch (count)
              {
                case 1:// chanel
                  Trax.Channel = s;
                  break;
                case 2://Batch No
                  Trax.BatchNo = s;
                  break;
                case 3://Buy Ccr
                  Trax.BuyCurrency = s;
                  break;
                case 4://Buy Amount

                  Trax.BuyAmount = decimal.Parse(s);
                  break;
                case 5://Customer rate
                  Trax.CusRate = decimal.Parse(s);
                  break;
                case 6://Sell Ccr
                  Trax.SellCurrency = s;
                  break;
                case 7://Sell Amount
                  Trax.SellAmount = decimal.Parse(s);
                  break;
                case 10://Value date
                  Trax.ValueDate = DateTime.Parse(s);

                  break;
                case 11://Cus seg
                  Trax.CusSeg = s;
                  break;
                case 12://Cust Master No
                  Trax.CustMasterNo = s;
                  break;
              }
            }
            catch (Exception ex) 
            {
              Logger.Error("WebRobot.App_code.FXFile::GetTransactionFX::transaction 12 column", ex);
            }
          }
        }
      }
      #endregion

      return Trax;
    }

    public bool IsBranchCodeFX(string sLine)
    {
      if (sLine.Contains("Branch") && sLine.IndexOf("Branch") == 0)
      {
        return true;
      }
      return false;
    }

    public bool IsCusName(string sLine)
    {
      tblConstantCollection listCus = new tblConstantCollection();
      listCus = tblConstantService.GettblConstantListByParaName("Customer Name");
      foreach (tblConstant cus in listCus)
      {
        if (string.Compare(sLine.ToLower(), cus.StringValue.ToLower()) == 0)
        {
          return true;
        }
      }
      return false;
    }


    #endregion
  }
}
